#region (c) 2009 Abdullin.com and Contributors

// Copyright (c) 2009 Abdullin.com and Contributors
// Site: http://abdullin.com/ncouch
// This code is released under the terms of the new BSD licence

#endregion

using System;
using System.Collections.Generic;
using System.IO;
using Lokad;
using NCouch.Rest;

namespace NCouch
{
	public sealed class CouchRequestSyntax
	{
		internal readonly CouchRestMethod Method;
		internal Maybe<Action<Stream>> Content { get; set; }
		internal string ContentType { get; set; }
		internal readonly string Query;
		internal readonly List<RestHeader> Headers = new List<RestHeader>();

		readonly CouchRestClient _builder;

		internal CouchRequestSyntax(CouchRestClient builder, CouchRestMethod method, string query)
		{
			_builder = builder;
			Method = method;
			Query = query;
			Content = Maybe<Action<Stream>>.Empty;
		}

		public CouchRequestSyntax WithContent<T>(T content)
		{
			Content = _builder.Serialize(content);
			ContentType = CouchRestClient.JsonContentType;
			return this;
		}

		public CouchRequestSyntax WithStream(Action<Stream> stream, string contentType)
		{
			Content = stream;
			ContentType = contentType;
			return this;
		}

		public CouchRequestSyntax WithHeaders(IEnumerable<RestHeader> headers)
		{
			Headers.AddRange(headers);
			return this;
		}
	}
}